package cn.diancan.util.spring;

import cn.diancan.dto.PurchaseSaleOrderStatisticsDto;
import cn.diancan.dto.query.PurchaseSaleOrderProductQuery;
import cn.diancan.model.types.PurchaseSaleOrderProductStatusType;
import cn.diancan.service.PurchaseSaleOrderService;
import cn.diancan.util.FtlUtils;
import cn.diancan.util.MailUtil;
import cn.diancan.util.Setting;
import cn.diancan.util.SettingUtils;
import cn.diancan.vo.manager.PurchaseSaleManagerOrderActionVo;
import cn.diancan.vo.other.Pager;

import java.util.HashMap;
import java.util.Map;

public class NotifyThread implements Runnable {
 
    private String basePath;
    private String   outOrderNumber; 
    
    /*private NotifyThread(PurchaseSaleOrder purchaseSaleOrder, SaleOrderVo saleOrderVo) {
	super();
	this.purchaseSaleOrder = purchaseSaleOrder;
	this.saleOrderVo = saleOrderVo;
    }*/

    public NotifyThread(String outOrderNumber,String basePath) {
	super();
	this.outOrderNumber = outOrderNumber;
	this.basePath = basePath;
    }
    

    @Override
    public void run() {
	// TODO Auto-generated method stub
	 try {
	     PurchaseSaleOrderService purchaseSaleOrderService = (PurchaseSaleOrderService) SpringContextUtil.getBean("purchaseSaleOrderService");
		   
	      //  String outOrderNumber ="JMHS11981479207617";
	      //  String basePath = "http://122.228.236.84:8080/taobaoClone/";
	     
	        FtlUtils ftlUtils = new FtlUtils();
	        ftlUtils.init(false);
	        Map<String,Object> root = new HashMap<String, Object>();
	        
	        
	        PurchaseSaleManagerOrderActionVo requestVo =new PurchaseSaleManagerOrderActionVo(); 
	        Pager pager = new Pager(); 
	        requestVo.setOutOrderNumber(outOrderNumber);  
	        
	        pager.setPageNumber(requestVo.getPageNumber());
		    pager.setPageSize(10);
		    
		    
		    PurchaseSaleOrderProductQuery query = requestVo.getQuery();
		    PurchaseSaleOrderStatisticsDto statisticsDto  = new PurchaseSaleOrderStatisticsDto();
		    pager =  purchaseSaleOrderService.findPagerBySaleOrderProduct(pager,query,statisticsDto);
		    
		    root.put("purchaseSaleOrderProductStatusTypeEnum", PurchaseSaleOrderProductStatusType.getSaleValues());
		    
		    root.put("pager", pager);
		    root.put("purchaseSaleOrderStatistics", statisticsDto);
		    root.put("requestVo", requestVo); 
		    root.put("basePath",basePath);
		    root.put("base", basePath);
		    root.put("login_manager_Id", 1);
	        //sale_order_product_list_template.ftl
		    ///views/ftl/manager/purchasesaleorder/sale_order_statistics_product_list_template.ftl
	        String html =ftlUtils.buildTemplate(root, "/views/ftl/manager/purchasesaleorder/sale_order_product_list_template.ftl");
	        
	         Setting setting= SettingUtils.getSetting(SettingUtils.getCommonSetting().getCurrent_site()) ; 
	        
	        
	         MailUtil.sendMail("订单通知",setting.getName() +"订单通知", html);
	  } catch (Exception e) { 
	    e.printStackTrace();
	}
    }
    
    /*
     *      String html = "<style>";
	    html += "   .sky-table{width:100%;text-align:center;border:none;background:#eaeaea;font-size:14px}.sky-thead{background:#4a5064;color:#FFFFFF;height:40px;background-color:#F5F6FA;color:#999}.sky-tbody{height:40px;background:#FFFFFF;color:#333333}";
	    html += "</style>";
     */

    




}
